/*
 * Copyright (C) 2011 CrystalRange
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.crystalrange.softwares.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.crystalrange.model.User;

// TODO: Auto-generated Javadoc
/**
 * The Class Software.
 *
 * @author Krzysiek
 */
public class Software {
    
    /** The id. */
    private Long id;
    
    /** The name. */
    private String name;
    
    /** The description. */
    private String description;
    
    /** The created date. */
    private Date createdDate;
    
    /** The created by. */
    private User createdBy;
    
    /** The software versions. */
    private List<SoftwareVersion> softwareVersions;
    
    /**
     * Instantiates a new software.
     */
    public Software() {
        this.softwareVersions = new ArrayList<SoftwareVersion>();
    }
    
    /**
     * Gets the id.
     *
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the id.
     *
     * @param id the new id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Gets the name.
     *
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name.
     *
     * @param name the new name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Gets the created by.
     *
     * @return the created by
     */
    public User getCreatedBy() {
        return createdBy;
    }

    /**
     * Sets the created by.
     *
     * @param createdBy the new created by
     */
    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    /**
     * Gets the created date.
     *
     * @return the created date
     */
    public Date getCreatedDate() {
        return createdDate;
    }

    /**
     * Sets the created date.
     *
     * @param createdDate the new created date
     */
    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    /**
     * Gets the description.
     *
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * Sets the description.
     *
     * @param description the new description
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Gets the software versions.
     *
     * @return the software versions
     */
    public List<SoftwareVersion> getSoftwareVersions() {
        return softwareVersions;
    }

    /**
     * Sets the software versions.
     *
     * @param softwareVersions the new software versions
     */
    public void setSoftwareVersions(List<SoftwareVersion> softwareVersions) {
        this.softwareVersions = softwareVersions;
    }
    
    /**
     * Adds the software version.
     *
     * @param softwareVersion the software version
     */
    public void addSoftwareVersion(SoftwareVersion softwareVersion) {
    	softwareVersion.setSoftware(this);
    	
    	if (!this.getSoftwareVersions().contains(softwareVersion)) {
    		this.getSoftwareVersions().add(softwareVersion);
    	}
    }
    
    /**
     * Removes the software version.
     *
     * @param softwareVersion the software version
     */
    public void removeSoftwareVersion(SoftwareVersion softwareVersion) {
    	softwareVersion.setSoftware(null);
    	
    	if (this.getSoftwareVersions().contains(softwareVersion)) {
    		this.getSoftwareVersions().remove(softwareVersion);
    	}
    }
}
